package com.dayaokeji.rhythmschoolstudent.client.common.exam;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.ListFragment;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.adapter.TestResultListAdapter;
import com.dayaokeji.server_api.ApiUtils;
import com.dayaokeji.server_api.api.ExamApi;
import com.dayaokeji.server_api.domain.TestResult;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import retrofit2.Call;

/**
 * Created by Gorden on 2017/10/24.
 * 考试结果列表
 */

public class TestResultListFragment extends ListFragment<TestResult,BaseViewHolder> {

    private static final String EXTRA_EXAM_ID = "exam_id";
    private int examId;

    public static TestResultListFragment newInstance(int examId) {

        Bundle args = new Bundle();
        args.putInt(EXTRA_EXAM_ID,examId);
        TestResultListFragment fragment = new TestResultListFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        examId = getArguments().getInt(EXTRA_EXAM_ID);

        setAdapter(new TestResultListAdapter());
        setRecyclerView();
    }

    private void setRecyclerView() {
        RecyclerView recyclerView = getRecyclerView();
        if (recyclerView != null) {
            recyclerView.setBackgroundColor(Color.WHITE);
            recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity())
                    .sizeResId(R.dimen.default_divider_height)
                    .colorResId(R.color.color_default_divider)
                    .build());
        }
    }

    @Override
    protected Call createCall(int offset, int max) {
        return ApiUtils.getApi(ExamApi.class).queryExamGradeTeacher(examId);
    }
}
